package com.cloudlibrary.mapper;

import com.cloudlibrary.domain.Record;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

/**
* @author FoxPrime
* @description 针对表【record】的数据库操作Mapper
* @createDate 2024-12-19 00:50:10
* @Entity com.cloudlibrary.domain.Record
*/
@Component
public interface RecordMapper  {
    @Insert("insert into record(" +
            "record_id,record_bookname,record_bookisbn,record_borrower,record_borrowtime,record_remandtime)" +
            "values(#{id},#{bookname},#{bookisbn},#{borrower},#{borrowtime},#{remandtime})"
    )
    Integer addRecord(Record record);

    @Select({"<script>"+
            "SELECT * FROM record " +
            "WHERE 1=1"+
            "<if test=\"borrower != null\">AND record_borrower like CONCAT('%', #{borrower}, '%')</if>"+
            "<if test=\"bookname != null\">AND record_bookname like CONCAT('%', #{bookname}, '%')</if>"+
            "order by record_remandtime desc" +
            "</script>"
    })
    @Results(id = "recordMap", value = {
            @Result(id = true,column = "record_id", property = "id"),
            @Result(column = "record_bookname", property = "bookname"),
            @Result(column = "record_bookisbn", property = "bookisbn"),
            @Result(column = "record_borrower", property = "borrower"),
            @Result(column = "record_borrowtime", property = "borrowtime"),
            @Result(column = "record_remandtime", property = "remandtime")
    })
    Page<Record> searchRecords(Record record);

}




